import React from 'react'
// 导入store
import { store } from '../../store'
// 导入action构建函数
import {sendAction} from '../../action'
import { useEffect } from 'react'
const Home = () => {
    const handleClick=()=>{
        const action=sendAction()
        // 发送一个action 要用dispatch 那就要用store
        store.dispatch(action)//需要action
    }

    // 当组件加载完毕后 来监听
   useEffect(()=>{
    store.subscribe(()=>{
        console.log('subscribe:',store.getState());
        
    })
    
   })
    return (
        <div>
            <button onClick={handleClick}>点击我，发送一个action</button>
            <div>{store.getState().value}</div>
        </div>
    )
}

export default Home
